﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Model;
using Controller;

namespace Trabajador
{
    public partial class CreateUser : Form
    {
        UserController pMan = new UserController();

        public CreateUser()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String user = txtUser.Text;
            String pass = txtPass.Text;
            String email = txtEmail.Text;
            int rol_id = Int32.Parse(rolesCombo.SelectedValue.ToString());

            Usuario u = new Usuario(user,pass,email);

            String result = pMan.registerUser(u,rol_id );

            if (result.Equals(""))
            {
                MessageBox.Show("El usuario ha sido registrado","Registro");
                this.Close();
            } else
            {
                MessageBox.Show(result,"Registro");
            }
        }

        private void CreateUser_Load(object sender, EventArgs e)
        {
            List<Rol> roles = pMan.getAllRoles();

            this.rolesCombo.DataSource = roles;
            this.rolesCombo.DisplayMember = "descripcion";
            this.rolesCombo.ValueMember = "id";
            this.rolesCombo.DropDownStyle = ComboBoxStyle.DropDownList;
        }
    }
}
